package Master.interfaces;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import Master.Resource;

public class ResourcePanelItem extends PanelItem {
	private JLabel image = new JLabel(new ImageIcon("client_images/gui/worker.png"));
	private JLabel resource_id = new JLabel("Resource ID");
	private JLabel hostname = new JLabel("Host name");
	private JLabel address = new JLabel("IP Address");
	private JLabel socket_port = new JLabel("Socket port");
	private JLabel cost = new JLabel("Cost per sec");
	
	private JLabel resource_id_data = new JLabel();
	private JLabel hostname_data = new JLabel();
	private JLabel address_data = new JLabel();
	private JLabel socket_port_data = new JLabel();
	private JLabel cost_data = new JLabel();
	
	public ResourcePanelItem(Resource this_resource)
	{
		super(this_resource.getID());
		
		resource_id_data.setText(""+this_resource.getID());
		hostname_data.setText(this_resource.getHostName());
		address_data.setText(this_resource.getAddress());
		socket_port_data.setText(""+this_resource.getPortNo());
		cost_data.setText(""+this_resource.getCost());
		
		initialiseGUI();
	}
	
	private void initialiseGUI()
	{
		this.setBorderStyle(BorderFactory.createEtchedBorder());
		
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		
		c.gridx = 0;
		c.gridy = 0;
		c.gridheight=5;
		c.insets=new Insets(3,3,3,3);
		//image.setBorder(BorderFactory.createEtchedBorder());
		this.addComponent(image,c);
		c.gridheight=1;
		
		c.insets=new Insets(1,5,1,5);
		c.gridx = 1;
		c.gridy = 0;
		this.addComponent(resource_id,c);
		
		c.gridx = 1;
		c.gridy = 1;
		this.addComponent(hostname,c);
		
		c.gridx = 1;
		c.gridy = 2;
		this.addComponent(address,c);
		
		c.gridx = 1;
		c.gridy = 3;
		this.addComponent(socket_port,c);
		
		c.gridx = 1;
		c.gridy = 4;
		this.addComponent(cost,c);
		
		c.gridx = 2;
		c.gridy = 0;
		this.addComponent(resource_id_data,c);
		
		c.gridx = 2;
		c.gridy = 1;
		this.addComponent(hostname_data,c);
		
		c.gridx = 2;
		c.gridy = 2;
		this.addComponent(address_data,c);
		
		c.gridx = 2;
		c.gridy = 3;
		this.addComponent(socket_port_data,c);
		
		c.gridx = 2;
		c.gridy = 4;
		this.addComponent(cost_data,c);
	}
}
